<?php
namespace app\index\controller;

use think\Db;
use think\facade\Request;

    /**
     * 首页控制器
     */
class Cate extends Base
{

    public function initialize()
    {
        parent::initialize();

    }

    public function index()
    {
        $where = [
            'status' => 1,
            'id' =>input('id'),
            'catid'=>Request::param('id'),
        ];
        dump($where);
        $archives = DB::name('article')
            ->where($where)
            ->order('create_time DESC,id DESC')
            ->paginate(10)
            ->each(function ($item,$key){
                $roles = Db::name('category')->where([['id','in',$item['catid']]])->column('catname');
                $item['catname'] = '';
                if($roles)
                    $item['catname'] = implode(',',$roles);
                return $item;
            });
        $whe = [
            'status' => 1,
            'catid' =>Request::param('id'),
            'flag' => 1,
        ];
        $is_archives = DB::name('article')
            ->where($whe)
            ->order('create_time DESC,id DESC')
            ->paginate(4)
            ->each(function ($item,$key){
                $roles = Db::name('category')->where([['id','in',$item['catid']]])->column('catname');
                $item['catname'] = '';
                if($roles)
                    $item['catname'] = implode(',',$roles);
                return $item;
            });
        $viewDate = [
            'archives' => $archives,
            'is_archives' => $is_archives,
        ];
        $this->assign($viewDate);
        return $this->fetch();
    }
}